package com.niuwa.p2p.service.impl.custService;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.core.utils.StringUtil;
import com.niuwa.p2p.dao.custservice.CustServiceGroupDao;
import com.niuwa.p2p.dao.custservice.CustServiceGroupMemberDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.entity.custservice.CustServiceGroup;
import com.niuwa.p2p.entity.custservice.CustServiceGroupMember;
import com.niuwa.p2p.service.custService.ICustGroupService;
@Service
public class CustGroupServiceImpl implements ICustGroupService{
	
	@Autowired
	private CustServiceGroupDao custServiceGroup;
	
	@Autowired
	private CustServiceGroupMemberDao groupMemberDao;
	
	@Override
	public List<CustServiceGroup> getOneKindGroup(String groupType) {
		return custServiceGroup.getOneKindGroup(groupType);
	}
	
	
	@Override
	public PageBean<CustServiceGroup> selectAllGroup(Map<String, Object> paramMap) {
		assert paramMap.get(PageQuery.PAGEQUERY) != null;
		if(!StringUtil.isEmpty((String) paramMap.get("conditions"))){	
			paramMap.put("conditions", String.valueOf(paramMap.get("conditions")).trim().replaceAll("%", "\\\\%").replaceAll("_", "\\\\_"));
		}
		int totalCount = custServiceGroup.selectCountGroupByConditions(paramMap);
		PageBean<CustServiceGroup> page = new PageBean<CustServiceGroup>(totalCount);
		page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(custServiceGroup.selectAllGroupByConditions(paramMap));
		return page;
	}


	@Override
	public List<CustServiceGroupMember> selectGroupMemberByGroupId(
			long groupId) {
		return groupMemberDao.selectGroupMemberByGroupId(groupId);
	}

}
